#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import pytest
import sys
from tools import times, send_mail
from tools.logger import Log
import common.globalvar as glovalvarparam

project = sys.argv[1]
glovalvarparam._init()
glovalvarparam.set_value('ip', sys.argv[2])

if __name__ == '__main__':
    try:
        log = Log().logger
        print("开始执行脚本")
        log.info("==================================" + times.datetime_strftime() + "===================================")
        # pytest.main(['test_case/jzsz/', '--alluredir', './report/allure_raw'])
        pytest.main(['test_case/jzsz/enterprise/test_sign_interestedresume.py', '--alluredir', './report/allure_raw'])
        if project == 'jzsz':
            # 生成Allure报告需要的数据存在. / report / allure_raw目录
            pytest.main(['test_case/jzsz/', '--alluredir', './report/allure_raw'])
            log.info("脚本执行完成")
        elif project == 'dmidd':
            pytest.main(['test_case/dmidd/', '--alluredir', './report/allure_raw'])

    except Exception as e:
        log.error("脚本批量执行失败！", e)
    try:
        log.info("开始执行报告生成")
        os.system('allure generate report/allure_raw -o report/allure_report --clean')
        log.info("报告生成完毕")
        print("报告生成完毕")
        # send_mail.send_report()
    except Exception as e:
        print("报告生成失败，请重新执行", e)
        log.error("报告生成失败，请重新执行", e)
        log.error('执行用例失败，请检查环境配置')
        raise